from webob import Response
from pyramid.chameleon_zpt import render_template
from pyramid.url import model_url
import logging


log = logging.getLogger('ampersands')


class OMEROBaseView(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request

    def listChildren(self):
        return self.context.values()

    def __call__(self):
        self.request.response_content_type = "text/xml"
        base_url = model_url(self.context, self.request)
        return {'view': self, 'context': self.context, "base_url": base_url}


def list_omero_types(context, request):
    data = {'type': [{'name': 'image', 'image': '/'},
            ]}
    xml = render_template('templates/omero_types.pt', data=data)
    return Response(xml, content_type='text/xml')


def forbidden_view(request):
    r = Response('forbidden')
    r.status = 401
    return r
